<?php
/**
 *
 *
 */
class Yz_Model_Field_Id
    extends Yz_Model_Field_Abstract
{

    const NOTNULL = true;
    protected $notnull = self::NOTNULL;

    /** Initialization value: primary assignment allows null in certain cases
     *      such as forms, uploads (i.e. creating a new item)
     *  @return
     */
    public function assignValue($value)
    {
        if (null === $value)
            return null;
        assert('is_numeric($value) and $value > 0');
        return (int)$value;
    }

    /** Test if a value is suitable for the property, possibly adjust
     *  @param mixed value
     *  @return the adjusted value
     *  @throw TypeError
     *  @throw ValueError
     */
    protected function _testValue($value)
    {
        if (! is_numeric($value))
            throw TypeError::_new_();
        $value = (int)$value;
        if ($value <= 0)
            throw ValueError::_new_();
        return $value;
    }
}
